<template>
	<view class="goods_list">
		<goods-list @goodsItemClick="goGoodsDetial" :goods="goods"></goods-list>
		<view class="isOver" v-if="flag">-----没有更多数据了-----</view>
	</view>
</template>

<script>
	import goodsList from '../../components/goods-list/goods-list.vue'
	
	export default {
		data() {
			return {
				pageindex:1,
				goods:[],
				flag:false
			}
		},
		methods: {
			//获取商品列表
			async getGoodsList(callBack){
				const res =await this.$myRequest({
					url:'/api/getgoods?pageindex='+this.pageindex
				})
				this.goods=[...this.goods,...res.data.message]
				callBack&&callBack()
			},
			goGoodsDetial(id){
				uni.navigateTo({
					url:'/pages/goods-detial/goods-detial?id='+id
				})
			}
		},
		onLoad() {
			this.getGoodsList()
		},
		onReachBottom() {
			if(this.goods.length<this.pageindex*10){
				return this.flag=true
			}
			this.pageindex++
			this.getGoodsList()
		},
		onPullDownRefresh() {
			this.pageindex=1
			this.goods=[]
			this.flag=false
			
			setTimeout(()=>{
				this.getGoodsList(()=>{
					uni.stopPullDownRefresh()
				})
			},1000)
		},
		components:{
			"goods-list":goodsList
		}
	}
</script>

<style>
	.goods_list{
		background: #eee;
	}
	
	.isOver{
		width: 100%;
		height: 50rpx;
		line-height: 50rpx;
		text-align: center;
		background: #fff;
		font-size: 28rpx;
	}

</style>
